package com.carserver.controller;

import com.carserver.common.Result;
import com.carserver.pojo.Count;
import com.carserver.service.CountDao;
import com.carserver.service.OrderFormDao;
import com.carserver.service.UserDao;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.persistence.criteria.CriteriaBuilder;

@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
@RestController
@RequestMapping("/count")
public class CountController {
    @Resource
    CountDao countDao;

    @Resource
    OrderFormDao orderFormDao;

    @Resource
    UserDao userDao;

    @GetMapping("/get")
    public Result get_count(){
        Integer people_all=userDao.getNumAll();
        Integer people_user=userDao.getNumUser();
        Integer people_manage=people_all-people_user;
        Integer evaluate5=orderFormDao.count5();
        Integer evaluate4=orderFormDao.count4();
        Integer evaluate3=orderFormDao.count3();
        Integer n0=orderFormDao.count_flag0();
        Integer n1=orderFormDao.count_flag1();
        Integer n2=orderFormDao.count_flag2();
        Integer n3=orderFormDao.count_flag3();
        Integer n4=orderFormDao.count_flag4();


        Count count=countDao.findById(1).get();
        count.setEvaluate_3(evaluate3);
        count.setEvaluate_4(evaluate4);
        count.setEvaluate_5(evaluate5);

        count.setPeople_all(people_all);
        count.setPeople_manage(people_manage);
        count.setPeople_user(people_user);
        count.setDingdan_0(n0);
        count.setDingdan_1(n1);
        count.setDingdan_2(n2);
        count.setDingdan_3(n3);
        count.setDingdan_4(n4);
        countDao.save(count);
        return Result.success(count);
    }

    @PostMapping("/change")
    public Result change(@RequestBody Count count){
        countDao.save(count);
        return Result.success();
    }

}
